package com.example.service.webhook.business.taobao.repository;

import javax.annotation.Resource;

import org.springframework.dao.EmptyResultDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import com.example.service.webhook.business.taobao.entity.UserInfoEntity;
import com.example.service.webhook.repository.base.BaseDAO;
import com.example.service.webhook.util.DateUtil;
/**
 * 这里用的是jdbctemplate，DAO层可以根据自己的业务来选择
 * ClassName: UserInfoRepository
 * date: 2016年7月19日 下午6:29:23   
 * @author yuandong  
 * @version   
 * @since JDK 1.6
 */
@Repository
public class UserInfoRepository extends BaseDAO<UserInfoEntity>{
	
	@Resource(name="templateTaobao")
    private JdbcTemplate jdbcTemplate;

    public JdbcTemplate getJdbcTemplate() {
		return jdbcTemplate;
	}
    
    public void saveUserInfo(UserInfoEntity entity) throws Exception  {
    	entity.setCreateTime(DateUtil.getCurrentDate());
    	entity.setLastModifyTime(DateUtil.getCurrentDate());
		this.add(entity);
    }
    
    public void updateUserInfo(UserInfoEntity entity) throws Exception  {
    	entity.setLastModifyTime(DateUtil.getCurrentDate());
		this.modify(entity);
    }
    
    public UserInfoEntity getUserInfo(String userId,String mappingId) throws Exception {
        String sql = "";
        String tableName = "t_taobao_userinfo";
        sql = "select * from " + tableName + " where userId=? and mappingId=?";
        UserInfoEntity pojo = null;
        try{
         pojo = (UserInfoEntity) queryOne(sql, new Object[] { userId,mappingId }, new UserInfoEntity());	
        }catch(EmptyResultDataAccessException e){
        	return null;
        }
        
        return pojo;
    }
    
    
}
